#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;


//method 1 test on 1337 online judge and pass all the test
double power(double x, int n)
{
    bool minus = false;
    if (n < 0) {n *= -1; minus = true;}
    if (n == 0) return 1;
    double ans = 1;

    while (n > 0) {
        if (n&1) {
            ans *= x;    
        }
        x *= x;
        n  = n >>1; 
    }

    return minus == true ? 1/ans : ans;
}


//method 2 
double power2(double x, int n)
{
    if (n == 0) return 1;
    if ( n < 0 ) return 1/power2(x, -n);

    double result = power2(x,n/2);
    
    if (n&1) {
        return x*result*result; 
    } else {
        return result*result;
    }
}

int main(int argc, char **argv)
{
    double result;
    result = power(2,2);
    cout << result << endl;
    result = power(2, -2);
    cout << result << endl;
    result = power2(2,2);
    cout << result << endl;
    result = power2(2, -2);
    cout << result << endl;

    return 0;
}
